<?php
/**
 * Created by PhpStorm.
 * User: prg
 * Date: 2017/3/3
 * Time: 19:28
 */

//管理员审核(更新)月报状态接口

require_once 'db.php';
require_once 'response.php';

header('content-type:text/html;charset:utf-8');
header('Access-Control-Allow-Origin:*');
header('Access-Control-Allow-Methods:GET');
header('Access-Control-Allow-Headers:x-requested-with,content-type');

$id = isset($_POST['reportId']) ?  $_POST['reportId'] : '';
$status = isset($_POST['status']) ? $_POST['status'] : '';

if(!is_numeric($id) || !is_numeric($status) || ($status!='0'&&$status!='1')) {
    return Response::show(401,'数据不合法');
}

try {
    $connect = Db::getInstance()->connect();
} catch (Exception $e) {
    return Response::show(403,'数据库连接失败',$e->getMessage());
}

$sql = "SELECT check_status FROM report WHERE report_id={$id}";
$res = $connect->query($sql);

if($res && $res->num_rows>0) {
    $res->free_result();
    if($status == '0') {
        $now = 1;
    } else {
        $now = 0;
    }

    $sql = "UPDATE report SET check_status={$now} WHERE report_id={$id}";
    $res = $connect->query($sql);

    $data = array(
        'nowStatus' => ''
    );

//注意这里并不是简单的审核，而是修改月报的审核状态
    if($res) {
        $data['nowStatus'] = $now;
        return Response::show(200,'用户月报审核状态更新成功',$data);
    } else {
        $data['nowStatus'] = $status;
        return Response::show(402,'用户月报审核失败,审核状态不改变',$data);
    }

} else {
    return Response::show(404,'找不到月报数据,id错误');
}



